//
//  MJLoadHeardView.m
//  Weike
//
//  Created by leirz on 14-5-12.
//  Copyright (c) 2014年 winupon. All rights reserved.
//

#import "MJLoadMoreView.h"
#import "MJRefreshConst.h"
#import "AppUtils.h"

@interface MJLoadMoreView()
{
    
    UIView *loadingView;
    UILabel *lineLabel;
    UIActivityIndicatorView *activityView;
}
@end

@implementation MJLoadMoreView

@synthesize hasMore;

- (id)init
{
    self = [super init];
    if (self) {
        self.hasMore = YES;
//        CGFloat height = SCREEN_HEIGHT + 100;
//        loadingView = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 30) / 2, -height + 60, 30, height)];
//        [self addSubview:loadingView];
 
        activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        activityView.frame = CGRectMake((SCREEN_WIDTH - 30) / 2, 60, 30, 30);
        [self addSubview:activityView];
        [activityView startAnimating];
        [AppUtils showViewBorder:self];
    }
    return self;
}

- (BOOL)isCustomView
{
    return YES;
}

+ (instancetype)header
{
    return [[MJLoadMoreView alloc] init];
}

#pragma mark - UIScrollView相关
#pragma mark 重写设置ScrollView
- (void)setScrollView:(UIScrollView *)scrollView
{
    [super setScrollView:scrollView];
    
    // 1.设置边框
    self.frame = CGRectMake(0, - MJRefreshViewHeight, scrollView.frame.size.width, 10);
}

#pragma mark - 状态相关
#pragma mark 设置最后的更新时间
- (void)setLastUpdateTime:(NSDate *)lastUpdateTime
{
   
}

#pragma mark 更新时间字符串
- (void)updateTimeLabel
{
    
}

#pragma mark 设置状态
- (void)setState:(MJRefreshState)state
{
    // 1.一样的就直接返回
    if (_state == state) return;
    
    // 3.调用父类方法
    [super setState:state];
    if (self.hasMore) {
        activityView.hidden = NO;
        //[activityView startAnimating];
    } else {
        activityView.hidden = YES;
        //[activityView stopAnimating];
    }
}

#pragma mark - 在父类中用得上
// 合理的Y值(刚好看到下拉刷新控件时的contentOffset.y，取相反数)
- (CGFloat)validY
{
    return _scrollViewInitInset.top;
}

// view的类型
- (int)viewType
{
    return MJRefreshViewTypeHeader;
}

@end
